package com.proj.config;

import com.proj.interceptor.ManagerLoginInterceptor;
import com.proj.interceptor.ShoppingLoginInterceptor;
import com.proj.util.SYS;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
public class WebMVCConfig implements WebMvcConfigurer {

    //资源处理器
    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        //静态文件处理器
        //定义D://easyupload中的资源访问路径
        //让springmvc添加一个处理器，访问静态资源
        //浏览器访问 easyfile/**文件名 时， 就访问这个资源处理器
        registry.addResourceHandler(SYS.FILE_UPLOAD_URL+"/**")
                .addResourceLocations("file:"+SYS.FILE_UPLOAD_DIR);
    }

    //网址拦截器
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        //拦截器，拦截所有的shopping/cart页面请求
        registry.addInterceptor(new ShoppingLoginInterceptor())
                    .addPathPatterns("/shopping/cart","/shopping/single","/shopping/userinfo","/shopping/settlement");

        registry.addInterceptor(new ManagerLoginInterceptor())
                .addPathPatterns("/sys/index","/sys/category","/sys/echarts","/sys/goods","/sys/order","/sys/user");
    }
}
